﻿  <?php include("conn.php");

  	//订单接口
    mysql_query('SET shopidS UTF8'); 

    $ordersid = $_REQUEST['ordersid'];

	$prize = array();
	
	$rert30=mysql_query("select * from goodsorders where ordersid='".$ordersid."'");	
	$rowf=mysql_fetch_array($rert30);


     //商铺信息
	$rert32=mysql_query("select * from shop where  shopid ='".$rowf['shopid']."'");
	$rowf2=mysql_fetch_array($rert32);

     //购物车（订单的商品信息，都在购物车里）
	$rert31=mysql_query("select * from car where ordersid ='".$ordersid."'");
	while ($rowf1=mysql_fetch_array($rert31)) {

		$rert34=mysql_query("select SUM(number) as total from car where ordersid ='".$ordersid."'");
		$rowf4=mysql_fetch_array($rert34);

		$rert33=mysql_query("select * from goods where goodsid ='".$rowf1['goodsid']."'");
		$rowf3=mysql_fetch_array($rert33);
		// 设置默认图
		$images = explode(',', $rowf3['images']);
		if ($images[$rowf3[defaultImgOrd]] !='') {
			$defaultImg = $images[$rowf3[defaultImgOrd]];
		}else{
			$defaultImg = $image[0];
		}
		// 设置默认图 end
		
	    $prize[] = array('title' =>$rowf3['title'],'fTitle' =>$rowf1[fTitle],'sTitle' =>$rowf1[sTitle],'price' =>$rowf1['price'],'goodsid' =>$rowf3['goodsid'],'number' =>$rowf1['number'],'images' =>$defaultImg );
	}
// 查找快递公司
	$query=mysql_query("select * from express_delivery where id=".$rowf['kuaidi']);
	$express_delivery=mysql_fetch_assoc($query);
	//查找快递公司 end
//0为待付款 1为待商家接单 2为待收货 3为待评价 4退款售后 5 交易成功 6交易关闭 7货到付款,8为商家接单，9为商家拒绝接单
$state = $rowf['state'];
//退货状态
$tuihuo_state = -1;
$tuihuoid=0;
$categroy_type = array();
if($state == 4){
	$tuihuo_query = mysql_query("select * from tuihuo where ordersid=".$ordersid);
	$tuihuo = mysql_fetch_assoc($tuihuo_query);
	if($tuihuo){
		$tuihuo_state = $tuihuo['state'];
	}
	// 查找分类类别
	$query = mysql_query("select * from categroy_type where id=(select categroy_type_id from categroy where cateid='".$rowf2['leimu']."')");
	$categroy_type = mysql_fetch_assoc($query);
		
	$query = mysql_query("select * from tuihuo where ordersid=".$ordersid);
	$tuihuo = mysql_fetch_assoc($query);
	
	if (is_array($tuihuo)) {
		$tuihuoid=$tuihuo[id];
	}
}
		
//收货人及电话
$shouhuoren_address = explode(',', $rowf['address']);
$address = $shouhuoren_address[0].$shouhuoren_address[1].$shouhuoren_address[2].$shouhuoren_address[3]."";
$shouhuoren =  $shouhuoren_address[4];
$shouhuoren_dianhua =  $shouhuoren_address[5];
$rowf['order_total_price'] = round($rowf['totalprice']*100 + $rowf['distribution_fee']*100 - $rowf['return_volume_price']*100 - $rowf['coupon_price']*100)/100;
		if((int)$rowf['buyFreightRisk'] == 1){
			$rowf['order_total_price'] = round($rowf['order_total_price']*100 + $rowf['freightRisk_price']*100)/100;
		}
$data = array('shopname' => $rowf2['name'],
	'shopid' => $rowf['shopid'],
	'dingdanhao' => $rowf['numbers'],
	'addtime' => $rowf['addtime'],
	'shouhuoren' =>$shouhuoren,
	'shouhuoren_dianhua' =>$shouhuoren_dianhua,
	'orderAddress' =>$address,
	'xia_dan_datetime'=> $rowf['xia_dan_datetime'],
	'fu_kuan_datetime'=> $rowf['fu_kuan_datetime'],
	'fa_huo_datetime'=> $rowf['fa_huo_datetime'],
	'shou_huo_datetime'=> $rowf['shou_huo_datetime'],
	'state' =>$state,
	'danhao'=>$rowf['danhao'],
	'freightRisk_price'=>$rowf['freightRisk_price'],
	'distribution_fee'=>$rowf['distribution_fee'],
	'buyFreightRisk'=>$rowf['buyFreightRisk'],
	'tuihuo_state'=>$tuihuo_state,
	'tuihuoid'=>$tuihuoid,
	'categroy_type'=>$categroy_type,
	'zongjia' => $rowf['totalprice'],
	'shopPhone' => $rowf2['phone'],
	'ordersid' => $_REQUEST['ordersid'],
	'pay_type'=>$rowf['pay_type'],
	'express_delivery'=>$express_delivery,
	'order_total_price'=>$rowf['order_total_price'],
	'msg'=>$rowf['msg'],
	'goodList' => $prize,
	'ping_lun_datetime' => $rowf['ping_lun_datetime']
	 );

echo json_encode(array('code' => 200,'msg' => "查询成功",'data' => $data ));

?>